import 'dart:io';

import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import '../common/flatPanel.dart';
import '../entry.dart';
import '../utils/screw.dart';

class ImagesPage extends StatefulWidget {
  ImagesPage({Key key, this.title: Entry.Images}) : super(key: key);

  final String title;

  @override
  _ImagesPageSate createState() {
    return _ImagesPageSate();
  }
}

class _ImagesPageSate extends State<ImagesPage> {
  final imgUrls = <String>[];

  @override
  void initState() {
    super.initState();
    imgUrls.add('https://www.usr.cn/Uploads/202011/10175440_10100.jpg');
    imgUrls.add('https://www.usr.cn/Uploads/202011/10175845_59418.jpg');
    imgUrls.add('https://www.usr.cn/Uploads/202011/10175936_46115.jpg');
    imgUrls.add('https://www.usr.cn/Uploads/202011/10180042_80884.jpg');
  }

  _pickFile() async {
    if (!Platform.isWindows) {
      var result = await FilePicker.platform.pickFiles();
      if (result != null) {
        Screw.showToast(context, result.files.single.path);
      }
    } else {
      Screw.showToast(context, '暂时不支持Windows版的FilePicker！');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: <Widget>[
          IconButton(
            icon: FaIcon(FontAwesomeIcons.crosshairs),
            onPressed: _pickFile,
          )
        ],
      ),
      body: FlatPanel(
          child: ListView.builder(
        itemCount: imgUrls.length,
        itemBuilder: (context, i) {
          return Image.network(imgUrls[i]);
        },
      )),
    );
  }
}
